/**
 * 
 */
package action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.mail.Session;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import pojo.Car;
import pojo.User;
import service.UserService;
import service.impl.UserServiceImpl;

/**
 * @author 陈冠伸
 *2016年6月14日
 */
public class BindAction extends ActionSupport{
	
	private Car car = new Car();
	private UserService userService =new UserServiceImpl();
	private String username;
	private String token;
	private Date bindtime;
	private String remark;
	private String binder;
	private String type;
	private String color;
	Map<String, Object> session = ActionContext.getContext().getSession();
	/*
	 * 绑定手表
	 */
	public String bind(){

		car.setBindtime(new Date());
		car.setUsername(username);
		car.setType(type);
		car.setColor(color);
		car.setRemark(remark);
		car.setBinder(binder);
		boolean b = userService.bind(car);
		if(b){
			session.put("binduser", car);
			return "bind_success";
		}else{
			return "bind_false";
		}
	}
	
	//校验
		public void validate(){
			String regex = "1[3|4|5|7|8|][0-9]{9}";
			if(!username.matches(regex)){
				this.addFieldError("userError", "请输入被监护人有效的手机号码");
			}
			if(!binder.matches(regex)){
				this.addFieldError("noBinder", "请输入监护人有效的手机号码");
			}

		}

	
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Date getBindtime() {
		return bindtime;
	}

	public void setBindtime(Date bindtime) {
		this.bindtime = bindtime;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String getBinder() {
		return binder;
	}

	public void setBinder(String binder) {
		this.binder = binder;
	}

	public Car getCar() {
		return car;
	}

	public void setCar(Car car) {
		this.car = car;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	




}
